package otherPractice;


import org.springframework.util.StringUtils;
import sun.misc.Launcher;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Stack;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.SynchronousQueue;


public class HelloWorld {

	public HelloWorld() {
	}



	public String HelloWorld() {
		return "Helloworld";
	}


	public static void test(List<String>a){
		a = new ArrayList<String>();
		a.add("abc");

	}


	private static Double[] stringToArray(String str) {
		if(!StringUtils.isEmpty(str)){
			String temString = str.substring(1,str.length()-1);
			String[] temArr = temString.split(",");
			List<Double> list = new ArrayList<>();

			for(String s : temArr){
				if (s != null && s.length() > 0) {
					list.add(Double.valueOf(s));
				}
			}
			return list.toArray(new Double[0]);
		}
		return null;
	}

	public static void main(String[] args) throws InterruptedException {
		System.out.println("welcome to here !!!");

//		for(int i=0;i<10;i++){
//			double temA = Math.random();
//			System.out.println(temA);
//			System.out.println(Double.valueOf(String.format("%.2f", temA)));
//		}

		int[] a= {1,2,3,4,5,6,7,8,9};

		System.out.println(Arrays.toString(a));

		Double[] doubles = {1.23,2.02,3.45,4.14,5.47};
		System.out.println(Arrays.toString(doubles));
		String str = "[1.20, 2.00, 3.58, 4.36, 5.89, 6.41]";
		Double[] temArr  = stringToArray(str);
		for(Double s : temArr){
			System.out.println(s);
		}














		long num = 0L;
		List<StringBuilder> oomPersonList = new ArrayList<>();
		StringBuilder sb = new StringBuilder();
		System.out.println("welcome to here !!!");
//		while (true){
//			num++;
//			oomPersonList.add(new StringBuilder("demo" + num));
//			System.out.println("======num=" + num);
//		}


//		int n=50; //初始饮料总数
//		int i=0; //兑换次数
//		while(true){
//			n-=3; //喝 3 瓶
//			n++; //兑换 1 瓶
//			i++; //兑换次数+1
//			System.out.println ("第"+ i +"次兑换");
//			if(n<3){
//				System.out.println ("共喝了"+(50+i)+"瓶");
//				break;
//			}
//
//		}









//		BlockingQueue<Integer> queue = new SynchronousQueue<>();
//		System.out.print(queue.offer(1) + " ");
//		System.out.print(queue.take() + " ");
//		System.out.print(queue.offer(2) + " ");
//		System.out.print(queue.offer(3) + " ");
//		System.out.print(queue.take() + " ");
//		System.out.println(queue.size());







//		String tem = "本体设备";
//		System.out.println(tem.substring(0,3));
//
//		Double obj1 = new Double("8.5");
//		Double obj2 = new Double("10.5");
//		int flag = obj1.compareTo(obj2);
//		System.out.println("flag=" + flag);
//
//		int[] a= {1,2,3,4,5,6,7,8,9};
//
//		System.out.println(Arrays.toString(srand(a)));

		//stackTest();

		//System.out.println(sqrt2());

//		Set<String> set = new HashSet<>();
//		set.add("A");
//		set.add("B");
//		set.add("C");
//		System.out.println("==== before === " + set);
//		//unmodifiableSet 使set 集合的元素不能再可变
//		set = Collections.unmodifiableSet(set);
//		System.out.println("==== after === " + set);
//
//		double num = 3.1455926;
//		String result = String.format("%.2f", num);
//		System.out.println(result);


//		int[][] a = {{1,2,3},{4,5,6},{4,2,4},{5,8,7}};
//		System.out.println("-------  length=  -----" + a.length);
//		System.out.println("-------  a[0.]length=  -----" + a[0].length);
//		System.out.println("-------  a[0.]length=  -----" + a[3][1]);


		
//		Thread.sleep(3000);
//		System.out.println(3|9);
//
//
//		System.out.println(3&9);
//
//		//System.out.println(3 && 9);
//
//		UUID uuid = UUID.randomUUID();
//		System.out.println(uuid);
//		UUID uuid1 = UUID.randomUUID();
//		System.out.println(uuid);
//		UUID uuid2 = UUID.randomUUID();
//		System.out.println(uuid2);
//
//		//死循环  for(;;){}
//		/*point:for(;;) {
//			int i = 0 ;
//			if(i < 20 ) {
//				i++;
//				System.out.println("welcome to 123455!!!");
//			}else {
//				break point;
//			}
//		}*/
//
//
//			// j=0 外层for循环
//			bbb:for(int i = 0 ; i< 10 ; i++) {
//				// i=0 内层for循环
//				if(i < 5) {
//					System.out.println("hello world"); // 1
//				}else {
//					break bbb;
//				}
//			}
//
	}


	//随机打乱
	public static int[] srand(int[] a) {
		int[] b=new int[a.length];
	    for(int i=0; i<a.length;i++) {
	    	//随机获取下标
			int tmp= (int)(Math.random()*(a.length-i)); //随机数:[ 0 ，a.length-i )
			b[i] =a[tmp];
			//将此时a[tmp]的下标移动到靠后的位置
			int change=a[a.length-i-1];
			a[a.length-i-1] =a[tmp];
			a[tmp] =change;
	    }
	    return b;
	}

	public static void stackTest(){
		Stack<Integer> integerStack = new Stack<>();
		for(int i = 0; i< 10 ; i++){
			integerStack.push(i);
			System.out.println("---- 栈压入数字=" + i);
		}
		while (integerStack.size() > 0){
			System.out.println("---- 栈输出数字=" + integerStack.pop());
		}



	}


	//根号2 精确到小数点10
	public static double sqrt2( ){
		double EPSINON = 0.0000000001;
		double low = 1.4, high = 1.5;
		double mid = (low + high) / 2;
		while ( high - low > EPSINON){
			if (mid*mid > 2){
				high = mid;
			}else {
				low = mid;
			}
			mid = (high + low) / 2;
		}
		return mid;
	}

}
